﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using KingSite.SyncDB.Core.Entity;
using System.Collections;

namespace KingSite.SyncDB.Core.Repository {
    public class TBRepository : BaseProvider {

        public IList<TBEntity> GetAllTBInfo() {
            String stmtId = "TBEntity.FindAll";
            IList<TBEntity> list = SqlMapper.QueryForList<TBEntity>(stmtId, null);
            return list;
        }

        public TBEntity GetTBEntity(int dbid, string tableName) {
            String stmtId = "TBEntity.Find";
            Hashtable ht = new Hashtable();
            ht.Add("DbId", dbid);
            ht.Add("TableName", tableName);
            TBEntity entity = SqlMapper.QueryForObject<TBEntity>(stmtId, ht);
            return entity;
        }

        public void UpdateRowTimeStamp(int id, string timeStamp) {
            TBEntity entity = new TBEntity();
            entity.Id = id;
            entity.LastTimeStamp = timeStamp;
            String stmtId = "TBEntity.UpdateRowTimeStamp";
            SqlMapper.Update(stmtId, entity);
        }


        public void InsertTBEntity(TBEntity entity) {
            if (entity == null) throw new ArgumentNullException("entity");
            String stmtId = "TBEntity.Insert";
            SqlMapper.Insert(stmtId, entity);
        }

        public void Delete(int tableId) {
            String stmtId = "TBEntity.Delete";
            SqlMapper.Delete(stmtId, tableId);
        }

        public void UpdateTBEntity(TBEntity entity) {
            if (entity == null) throw new ArgumentNullException("entity");
            String stmtId = "TBEntity.Update";
            SqlMapper.Update(stmtId, entity);
        }
        
    }
}
